# -*-coding:utf-8 -*-
from django.http import HttpResponse, Http404
from django.http import HttpResponseRedirect
from django.template import Context
from django.template import RequestContext
from forfood.customer.models import Customer
from forfood.restaurant.models import Restaurant
from forfood.star.models import Star
from forfood.helpers.user_helper import *
from django.shortcuts import render_to_response

def verify_email(request, uid, code):
    try:
        customer = Customer.objects.get(id = uid)
    except:
        customer = None
    
    if customer and customer.activate(code):
        customer.is_active = True
        customer.save()
        info = "%s,感谢您的注册，邮箱已激活。开始订餐"%customer.name.encode('utf8')
        return render_to_response('main/main.html',
                                  RequestContext(request, {'info':info})
                                  )
    else:
        info = "激活有误，请确认使用的激活链接是否为邮件中提供的链接。重新发送激活邮件到我的邮箱"
        return render_to_response('main/main.html',
                                  RequestContext(request, {'info':info})
                                  )
def customer_star_restaurant(request, rid):
    customer = find_customer(request.user)
    if not customer:
        #do something
        print "no customer"
        raise Http404
    
    try:
        restaurant = Restaurant.objects.get(id = rid)
    except:
        restaurant = None
        
    if not restaurant:
        #do something
        print "no restaurant"
        raise Http404    
    
    try:
        star = customer.star_set.get(restaurant = restaurant)
    except:
        star = None
        
    if star:
        star.delete()
    else:
        star = Star.objects.create(customer=customer, restaurant=restaurant)
    
    raise Http404 